var NumberContainers = function () {
  this.nums = new Map();
  this.heaps = new Map();
};

NumberContainers.prototype.change = function (index, number) {
  const oldNumber = this.nums.get(index);
  this.nums.set(index, number);
  if (!this.heaps.has(number)) {
    this.heaps.set(number, new MinPriorityQueue());
  }
  this.heaps.get(number).enqueue(index);
};

NumberContainers.prototype.find = function (number) {
  if (!this.heaps.has(number)) {
    return -1;
  }
  const heap = this.heaps.get(number);
  while (!heap.isEmpty() && this.nums.get(heap.front()) !== number) {
    heap.dequeue();
  }
  return heap.isEmpty() ? -1 : heap.front();
};
